package org.xwb.future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class CompletableFutureDemo03 {
    public static void main(String[] args) throws InterruptedException {
        // getNow()，如果没算完，先拿个假值用着先，原来的计算还是继续
        CompletableFuture.supplyAsync(() -> {
            return 10;
        }).handle((r,e)->{
            System.out.println("------1");
            System.out.println(r);
            int i = 10/0;
            return r+1;
        }).handle((r,e)->{
            System.out.println("------2");
            System.out.println(r);
            return r+1;
        }).handle((r,e)->{
            System.out.println("------3");
            System.out.println(r);
            return r+1;
        }).whenComplete((r,e)->{
            System.out.println(r);
        }).exceptionally(e -> {
            e.printStackTrace();
            return null;
        });

    }
}
